package demo1.java.Init;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-04-18
 * Time: 21:00
 */

@Component
public class Test1 implements BeanPostProcessor, BeanNameAware{

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("前置方法");
        return bean;
        // 初始化之前执行的逻辑
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("后置方法");
        return bean;
        // 初始化之后执行的逻辑
    }

    @PostConstruct
    public void doPostConstruct() {
        System.out.println("这是注解初始化方法!");
    }

    public void say() {
        System.out.println("这是 test1 的 say 方法");
    }

    @PreDestroy
    public void doPreDestroy() {
        System.out.println("执行 test1 中 bean 销毁");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("各种通知 -> " + s);
    }

    public void MyInit() {
        System.out.println("XML 初始化");
    }
}
